package com.simon.nvwo.modules;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * JDBC Example
 */
public class JDBCExample {

    public static void connectExample(String userId,String password){

        try {
            //加载驱动器类，执行类的静态方法(对应的驱动类将自己注册到DriverManager）
            Class.forName("Oracle.jdbc.driver.OracleDriver");

            Connection conn = DriverManager.getConnection("", userId, password);

            Statement stmt = conn.createStatement();

            stmt.executeUpdate("update student set name ='Harry' where id =1");

            ResultSet rset = stmt.executeQuery("select id,name from student where id =1");

            while(rset.next()){
                System.out.println("id: "+rset.getString("id")+",name: "+rset.getString("name"));
            }

        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
